Skip to content

Update constructor TypeToTypeInfoMarshaler() signature to static #2536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 5, 2019

Conversation

EugeneKramer
Copy link
Contributor

@EugeneKramer EugeneKramer commented Jun 3, 2019

Summary

Update constructor TypeToTypeInfoMarshaler() signature to static for C#, VB.Net, C++ to match the ILAsm static signature and constructor description: Provides the static class constructor.

Edit 1:
Updates the signatures of the 4 constructors in System.Runtime.InteropServices.CustomMarshalers Namespace to public static.

  1. EnumerableToDispatchMarshaler Constructor
  2. EnumeratorToEnumVariantMarshaler Constructor
  3. ExpandoToDispatchExMarshaler Constructor
  4. TypeToTypeInfoMarshaler Constructor

Edit 2:
Please note that public static constructors also go against security warning - CA2121: Static constructors should be private

Fixes #2529

Update constructor TypeToTypeInfoMarshaler() signature to static for C#, VB.Net, C++ to match the ILAsm static signature and constructor description - "Provides the static class constructor."

Resolves dotnet#2529
@@ -36,11 +36,11 @@
</Docs>
<Members>
<Member MemberName=".cctor">
<MemberSignature Language="C#" Value="public TypeToTypeInfoMarshaler ();" />
<MemberSignature Language="C#" Value="public static TypeToTypeInfoMarshaler ();" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really a public static constructor? I don't have .NET 1.1 (API browser claims that it's a latest version where this member is available), but in modern environment one cannot declare static constructor as public in C#, it generates compiler error CS0515.

Is there even a reason why API Docs should include static constructor? It is not really an "API", in a sence that one cannot use it directly. Moreover, currently the docs do not seem to provide any useful information about it, besides the fact it was removed in .NET 2.0.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're correct. It's a static constructor for a public class. I've removed the public access modifier for the C# and VB.Net static constructor. C++ does not support static constructors, so I've reverted the addition of the static modifier.

While a static constructor cannot be accessed directly, it is called prior to any first instance/usage of the type, which can lead to unusual exceptions such as TypeInitializationException which explicitly note "What often makes this exception difficult to troubleshoot is that static constructors are not always explicitly defined in source code." As such, the presence of a static constructor should be noted in the documentation.

A deprecated static constructor is listed for each of the 4 classes in the System.Runtime.InteropServices.CustomMarshalers Namespace. A separate page for the static constructors is probably unnecessary, but their presence should be noted as a remark.

Appreciate the feedback!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting this PR and raising the issue of a static constructor appearing in our doc set, @EugeneKramer. Since method signatures are gathered using reflection, I'm not sure that the changed signature won't be overwritten by the next reflection. But I'm also not sure why a static constructor is documented in the first place -- though I don't recall whether 2.0 introduced a change in the way static constructors were handled from 1.0/1.1.

@dend @joelmartinez, do you have any sense of why this constructor is marked as public and appears in the documentation? My guess would be that this is the only static constructor documented in the managed reference.,

I would think that the ILAsm signature also needs to change, although I no longer have any .NET Framework 1.1 assemblies.

For the moment, I'll mark this PR as blocked.

Copy link
Contributor

@mairaw mairaw Jun 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MSDN also had this constructor:
https://msdn.microsoft.com/en-us/library/03faz537(v=vs.80).aspx?toc=xxx

with the same signature that @EugeneKramer is proposing.

@rpetrusha you can access any version of the assemblies at https://apidrop.visualstudio.com/_git/binaries?path=%2Fdotnet&version=GBmaster

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apisof.net also lists this constructor, so I think it's fine to have it if we fix the signature
https://apisof.net/catalog/System.Runtime.InteropServices.CustomMarshalers.TypeToTypeInfoMarshaler..cctor()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still find this bizarre, but the static constructor is clearly public in .NET Framework 1.1. So correcting the syntax is appropriate. Is the correct syntax likely to be overwritten, @mairaw?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the correct syntax likely to be overwritten

Yes ... this needs to be fixed in mdoc's signature formatters. It will reset these next time an update is run.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rpetrusha - As mentioned earlier, there are public static constructors listed for each of the 4 classes in the System.Runtime.InteropServices.CustomMarshalers Namespace with the same public signature. If this PR is going through, should each of their signatures be updated...or should a separate PR be opened?

System.Runtime.InteropServices.CustomMarshalers Namespace:

Provides the static class constructor.

  1. EnumerableToDispatchMarshaler Constructor
  2. EnumeratorToEnumVariantMarshaler Constructor
  3. ExpandoToDispatchExMarshaler Constructor
  4. TypeToTypeInfoMarshaler Constructor

All were deprecated in .Net 2.0.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per dotnet#2536 (comment)
Removed the public access modifier for the C# and VB.Net static constructor. C++ does not support static constructors, so I've reverted the addition of the static modifier.
@rpetrusha rpetrusha added the blocked Indicates issues or PRs that are blocked for some reason label Jun 3, 2019
@rpetrusha rpetrusha added this to the June 2019 milestone Jun 3, 2019
@rpetrusha rpetrusha added ✨ 1st-time dotnet-api-docs contributor! Indicates PRs from new contributors to the dotnet-api-docs repository and removed blocked Indicates issues or PRs that are blocked for some reason labels Jun 4, 2019
Copy link

@rpetrusha rpetrusha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for correcting the C# and Visual Basic syntax, @EugeneKramer. We also need to add the public access modifier, since the static constructor was public in .NET Framework 1.1.

@rpetrusha
Copy link

Thanks again for submitting this PR, @EugeneKramer, as well as for making the additional changes. And thanks for your patience as we've tried to get this sorted out. I've approved your PR, and I'll merge once our internal build completes successfully.

@rpetrusha
Copy link

Sorry, @EugeneKramer. I didn't notice your earlier comment about the three additional constructors. Yes, their syntax should also be modified. If you'd like to make the change, you can do it in either this PR or a separate PR. If you'd prefer, we could also do it in a separate PR.

…c static for VB.NET & C#

Update constructor EnumerableToDispatchMarshaler() signature to public static for VB.NET & C# per 
dotnet#2536
@dnfclas
Copy link

dnfclas commented Jun 5, 2019

CLA assistant check
All CLA requirements met.

…blic static for VB.NET & C#

Update constructor EnumeratorToEnumVariantMarshaler() signature to public static for VB.NET & C# per 
dotnet#2536
… for VB.NET & C#

Update constructor ExpandoToDispatchExMarshaler() signature to public static for VB.NET & C# per 
dotnet#2536
@EugeneKramer
Copy link
Contributor Author

EugeneKramer commented Jun 5, 2019

@rpetrusha
Copy link

Thank you so much for making the additional changes, @EugeneKramer! I'll merge your PR now. The changes should be live on docs.microsoft.com in the next day or two.

@rpetrusha rpetrusha merged commit 3bbaa66 into dotnet:master Jun 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ 1st-time dotnet-api-docs contributor! Indicates PRs from new contributors to the dotnet-api-docs repository
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Static contructor's C# syntax string is missing static
6 participants